package com.tenllo.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tenllo.bean.UserInfo;
import com.tenllo.util.DbConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by maxl on 2017/7/6.
 */

@Controller
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserInfo userInfo;

    @RequestMapping(value="/register", produces = "application/json; charset=utf-8")
    @ResponseBody
    public  String userInfo(HttpServletRequest request){

        userInfo = DbConnection.register(request, userInfo);

        ObjectMapper mapper = new ObjectMapper();
        String json = "";
        try {
            json = mapper.writeValueAsString(userInfo);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return json;
    }

    @RequestMapping("/home")
    public  String home(){

        return "home";
    }
}
